<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>LinkedChat招聘网</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/public/static/css/Register.css">
    <script src="${pageContext.request.contextPath}/public/static/js/jquery-3.6.0.min.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/public/static/css/bootstrap.css">
    <link href="${pageContext.request.contextPath}/public/static/images/login_icon.ico" rel="shortcut icon">
</head>
<body>
    <div class="img">
        <div class="log register">
            <div class="myk">
                <div id="logs">
                    注册
                </div>

                <!-- 登录身份选择 -->
                <div class="formItem3">
                    <input type="button" value="我要找工作" class="butto1">
                    <input type="button" value="我要招聘" class="butto2">
                </div>

<%--                <!-- 手机号输入框  -->--%>
<%--                <div class="formItem2">--%>
<%--                    <label class="yonghu">手机号：</label>--%>
<%--                    <input type="text" id="Registertel" class="textinput userpho" placeholder="请输入手机号" ><!-- value="${result.data.personTel}" -->--%>
<%--                </div>--%>
<%--                <i class="msgTip2 userphoTip">  </i>--%>

<%--                <div class="formItem2">--%>
<%--                    <label  class="yonghu">用户名：</label>--%>
<%--                    <input type="text" id="Registername" class="textinput useremail"placeholder="请输入账户" >--%>
<%--                </div>--%>
<%--                <i class="msgTip2 useremailTip">  </i>--%>

<%--                <div class="formItem2">--%>
<%--                    <label  class="yonghu" >&nbsp;密&nbsp;&nbsp;码&nbsp;：</label>--%>
<%--                    <input id="Registerpassword" type="password"class="textinput userpwd" placeholder="请输入密码">--%>
<%--                </div>--%>
<%--                <i class="msgTip2 userpwdTip">  </i>--%>
                <li class="formItem2">
                    <label class="yonghu">手机号：</label>
                    <input type="text" placeholder="手机号码" class="textinput Registertel userpho" id="personTel" name="userTel">
                </li>
                <i class="msgTip2 userphoTip">  </i>
                <div class="formItem2">
                    <label  class="yonghu" >&nbsp;密&nbsp;&nbsp;码&nbsp;：</label>
                    <input id="Registerpassword" type="password"class="textinput userpwd" placeholder="请输入密码">
                </div>
                <i class="msgTip2 userpwdTip">  </i>
                <li class="formItem2" style="padding: 0 0 0 200px;">
                    <input type="text" placeholder="验证码" class="textinput" maxlength="6" id="code" style="width: 90px">
                    <input type="button" id="btn" class="btn btn-info btn-lg" value="获得验证码" style="font-size: 10px; height: 35px;">
                </li>
                <!-- 登录button -->
                <button id="Registerbutton" class="inputs submitBtn loginfail1" ><a href="#" style="text-decoration: none;color: black;">注册</a></button>
                <div class="logi"><a href="${pageContext.request.contextPath}/public/Person/Login.jsp">已有账号？去登录</a></div>
            </div>

        </div>
    </div>

<script src="${pageContext.request.contextPath}/public/static/js/registers.js"></script>
<script>



    var url = "${pageContext.request.contextPath}/personCenter/save";
    $("#Registerbutton").click(function (){
        var personTel = $("#personTel").val();
        // var personUsername = $("#Registername").val();
        var personPassword =$("#Registerpassword").val();
        // var data="personTel= "+personTel+"&personUsername="+personUsername+"&personPassword="+personPassword;
        var data="personTel= "+personTel+"&personPassword="+personPassword;
        console.log(data)
        $.post(url,data,function(result){
            if (code == "") {
                $("#loginfail1").text("请输入验证码！")
            }else if ( sms != code){
                $("#loginfail1").text("验证码错误！")
            }
            console.log("注册成功")
            window.alert(result.reason)
            sessionStorage.setItem("personTel",personTel)
            sessionStorage.setItem("personPassword",personPassword)
            window.location.href="${pageContext.request.contextPath}/public/Person/CaptchLogin.jsp"
        });
    })

var button =document.getElementById('btn');
button.onclick=function (){
    button.disabled ='disabled';
    var time = 60;
    var timer =setInterval(function (){
        if (time == -1){
            clearInterval(timer)
            button.disabled ='';
            button.value ='获取验证码';
        }else {
            button.value =time +'秒后重新获取';
            time--;
        }
    },1000)
}

var sms ="";
    //发送验证码
    $(".btn").click(function (){
        sendCode()
    })
    function sendCode(){

        // var sms = "";
        var phone = $("#personTel").val();
        console.log("登陆的手机号:"+phone);
        if (phone != ""){

            $.ajax({
                url : "${pageContext.request.contextPath}/registerSend",
                type : "post",
                dataType : "text",
                async:false,
                data: {
                    "phone" : phone
                },
                success:function (result) {
                    console.log("............");
                    console.log(result)
                    console.log(typeof result)
                    sms = JSON.stringify(result).slice(52,58);
                    // console.log(typeof sms[2]);
                    console.log(sms)
                    console.log("code:"+ sms);
                    //    console.log("sms:"+sms)
                    alert("发送成功");
                }
            });
            return sms;
            // console.log("sms:"+sms);
        }else {
            $("#loginfail1").text("请输入手机号")
            return false;
        }
    }
</script>

</body>
</html>
